using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Perovich.GameObjects.Interfaces;

namespace Perovich.GameObjects.Controls.GameStates
{
    /// <summary>
    /// A <see cref="Screen"/> class specialized to act as a GameState. Used by the <see cref="GameStateManager"/>
    /// </summary>
    public class GameState : Screen
    {
        /// <summary>
        /// Runs a provided function on this game state. Useful for initializing states.
        /// </summary>
        /// <param name="initializer">The function to run.</param>
        /// <example>
        /// <code>
        /// GameStateManager.MakeState("State1",this);
        /// GameStateManager.States["State1"].InitState(s =>
        /// {
        ///     b1 = new Button(s);
        ///     b1.Depth = 0;
        ///     b2 = new Button(s);
        ///     b2.Depth = 0;
        ///     b2.Text = "Swap!!";
        ///     b2.Margin = new Thickness(10);
        ///     b2.Border = new Thickness(10);
        ///     b2.ForegroundColor = Color.Black;
        ///     b2.BackgroundColor = Color.Red;
        ///     b2.BorderColor = Color.Blue;
        ///     b2.Clicked += new EventHandler(b2_Clicked);
        ///     obj1 = new BoundedObject2D(s);
        ///     obj2 = new BoundedObject2D(s);
        /// });
        /// </code>
        /// </example>
        public void InitState(Action<GameState> initializer)
        {
            if (initializer == null)
                throw new ArgumentNullException("initializer");
            initializer(this);
        }

        internal GameState(ICanHoldComponents game)
            : base(game)
        {
            Active = false;
            UpdateOrder = 1;
        }

        /// <summary>
        /// Allows the <see cref="GameState"/> to load any required content.
        /// </summary>
        protected override void LoadContent()
        {
            Width = this.GraphicsDevice.Viewport.Width;
            Height = this.GraphicsDevice.Viewport.Height;
            base.LoadContent();
        }
    }
}
